//
//  NewRegistVC.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2021/3/23.
//  Copyright © 2021 吕晶. All rights reserved.
//

#import "NewRegistVC.h"
#import "RegistDelegateVC.h"
#import "CommitSuccessVC.h"

@interface NewRegistVC () {
    BOOL isAgree;
    int carStatus;//1-单车 2-多车
}

@property (nonatomic, strong) UITextField *inviteCodeField;//邀请码
@property (nonatomic, strong) UILabel *line1;
@property (nonatomic, strong) UIView *btnView;
@property (nonatomic, strong) UIButton *duoBtn;//多车
@property (nonatomic, strong) UIButton *danBtn;//单车
@property (nonatomic, strong) UITextField *carCodeField;//车牌号
@property (nonatomic, strong) UILabel *line2;
@property (nonatomic, strong) UITextField *supplierField;//物流商名称
@property (nonatomic, strong) UILabel *line3;
@property (nonatomic, strong) UITextField *emailField;//邮箱
@property (nonatomic, strong) UILabel *line4;
@property (nonatomic, strong) UITextField *phoneField;//电话
@property (nonatomic, strong) UILabel *line5;
@property (nonatomic, strong) UITextField *phoneCodeField;//验证码
@property (nonatomic, strong) UIButton *getCodeBtn;
@property (nonatomic, strong) UILabel *line6;
@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIButton *agreeBtn;
@property (nonatomic, strong) UIButton *delegateBtn;
@property (nonatomic, strong) UIButton *commitBtn;

@end

@implementation NewRegistVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"云车主注册";
    isAgree = YES;
    carStatus = 1;
    [self configUI];
}

- (void)configUI {
    self.view.backgroundColor = [UIColor whiteColor];
    
    UILabel *title1Lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 17)];
    title1Lab.text = @"邀请码";
    title1Lab.font = BoldFontOfSize(16);
    title1Lab.textColor = HexColor(0x2B2C44);
    self.inviteCodeField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10, ScreenW - 40, 40)];
    self.inviteCodeField.placeholder = @"选填 请输入";
    self.inviteCodeField.font = MediumFontOfSize(16);
    self.inviteCodeField.textColor = HexColor(0x2B2C44);
    self.inviteCodeField.keyboardType = UIKeyboardTypeNumberPad;
    self.inviteCodeField.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:self.inviteCodeField];
    self.inviteCodeField.leftView = title1Lab;
    self.inviteCodeField.leftViewMode = UITextFieldViewModeAlways;
    [self.inviteCodeField addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
    
    self.line1 = [[UILabel alloc] initWithFrame:CGRectMake(20, self.inviteCodeField.nim_bottom + 10, ScreenW - 20, 1)];
    self.line1.backgroundColor = HexColor(0xF2F2F5);
    [self.view addSubview:self.line1];
    
    UILabel *title2Lab = [[UILabel alloc] initWithFrame:CGRectMake(20, self.line1.nim_bottom + 15, 80, 17)];
    title2Lab.text = @"拥有车辆数";
    title2Lab.font = BoldFontOfSize(16);
    title2Lab.textColor = HexColor(0x2B2C44);
    [self.view addSubview:title2Lab];
    
    UIButton *noticeBtn = [UIButton new];
    noticeBtn.nim_width = 16;
    noticeBtn.nim_height = 16;
    noticeBtn.nim_left = title2Lab.nim_right + 10;
    noticeBtn.nim_centerY = title2Lab.nim_centerY;
    [noticeBtn setImage:[UIImage imageNamed:@"icon_reject_regist"] forState:0];
    [noticeBtn addTarget:self action:@selector(noticeClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:noticeBtn];
    
    self.btnView = [UIView new];
    self.btnView.nim_width = 94;
    self.btnView.nim_height = 32;
    self.btnView.nim_left = ScreenW - 20 - 94;
    self.btnView.nim_centerY = noticeBtn.nim_centerY;
    self.btnView.backgroundColor = HexColor(0xF2F2F5);
    self.btnView.layer.masksToBounds = YES;
    self.btnView.layer.cornerRadius = 16;
    [self.view addSubview:self.btnView];
    
    self.duoBtn = [[UIButton alloc] initWithFrame:CGRectMake(3, 3, 44, 26)];
    [self.duoBtn setTitle:@"多车" forState:0];
    self.duoBtn.layer.masksToBounds = YES;
    self.duoBtn.layer.cornerRadius = 13;
    self.duoBtn.titleLabel.font = BoldFontOfSize(12);
    self.duoBtn.backgroundColor = HexColor(0xF2F2F5);
    [self.duoBtn setTitleColor:HexColor(0x585974) forState:0];
    [self.duoBtn addTarget:self action:@selector(changeClick) forControlEvents:UIControlEventTouchUpInside];
    [self.btnView addSubview:self.duoBtn];
    
    self.danBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.duoBtn.nim_right, 3, 44, 26)];
    [self.danBtn setTitle:@"单车" forState:0];
    self.danBtn.layer.masksToBounds = YES;
    self.danBtn.layer.cornerRadius = 13;
    self.danBtn.titleLabel.font = BoldFontOfSize(12);
    self.danBtn.backgroundColor = HexColor(0x3D68EB);
    [self.danBtn setTitleColor:HexColor(0xffffff) forState:0];
    [self.danBtn addTarget:self action:@selector(changeClick) forControlEvents:UIControlEventTouchUpInside];
    [self.btnView addSubview:self.danBtn];
    
    self.carCodeField = [[UITextField alloc] initWithFrame:CGRectMake(20, self.btnView.nim_bottom + 10, ScreenW - 40, 40)];
    self.carCodeField.placeholder = @"请输入车牌号";
    self.carCodeField.font = MediumFontOfSize(16);
    self.carCodeField.textColor = HexColor(0x2B2C44);
    self.carCodeField.textAlignment = NSTextAlignmentRight;
    self.carCodeField.keyboardType = UIKeyboardTypeDefault;
    [self.view addSubview:self.carCodeField];
    
    self.line2 = [[UILabel alloc] initWithFrame:CGRectMake(20, self.carCodeField.nim_bottom + 10, ScreenW - 20, 1)];
    self.line2.backgroundColor = HexColor(0xF2F2F5);
    [self.view addSubview:self.line2];
    
    UILabel *title3Lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 17)];
    title3Lab.text = @"车主名称";
    title3Lab.font = BoldFontOfSize(16);
    title3Lab.textColor = HexColor(0x2B2C44);
    self.supplierField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10 + self.line2.nim_bottom, ScreenW - 40, 40)];
    self.supplierField.placeholder = @"请输入";
    self.supplierField.font = MediumFontOfSize(16);
    self.supplierField.textColor = HexColor(0x2B2C44);
    self.supplierField.keyboardType = UIKeyboardTypeDefault;
    self.supplierField.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:self.supplierField];
    self.supplierField.leftView = title3Lab;
    self.supplierField.leftViewMode = UITextFieldViewModeAlways;
    
    self.line3 = [[UILabel alloc] initWithFrame:CGRectMake(20, self.supplierField.nim_bottom + 10, ScreenW - 20, 1)];
    self.line3.backgroundColor = HexColor(0xF2F2F5);
    [self.view addSubview:self.line3];
    
    UILabel *title4Lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 17)];
    title4Lab.text = @"邮箱";
    title4Lab.font = BoldFontOfSize(16);
    title4Lab.textColor = HexColor(0x2B2C44);
    self.emailField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10 + self.line3.nim_bottom, ScreenW - 40, 40)];
    self.emailField.placeholder = @"请输入";
    self.emailField.font = MediumFontOfSize(16);
    self.emailField.textColor = HexColor(0x2B2C44);
    self.emailField.keyboardType = UIKeyboardTypeDefault;
    self.emailField.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:self.emailField];
    self.emailField.leftView = title4Lab;
    self.emailField.leftViewMode = UITextFieldViewModeAlways;
    
    self.line4 = [[UILabel alloc] initWithFrame:CGRectMake(20, self.emailField.nim_bottom + 10, ScreenW - 20, 1)];
    self.line4.backgroundColor = HexColor(0xF2F2F5);
    [self.view addSubview:self.line4];
    
    UILabel *title5Lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 17)];
    title5Lab.text = @"电话";
    title5Lab.font = BoldFontOfSize(16);
    title5Lab.textColor = HexColor(0x2B2C44);
    self.phoneField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10 + self.line4.nim_bottom, ScreenW - 40, 40)];
    self.phoneField.placeholder = @"请输入";
    self.phoneField.font = MediumFontOfSize(16);
    self.phoneField.textColor = HexColor(0x2B2C44);
    self.phoneField.keyboardType = UIKeyboardTypeNumberPad;
    self.phoneField.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:self.phoneField];
    self.phoneField.leftView = title5Lab;
    self.phoneField.leftViewMode = UITextFieldViewModeAlways;
    
    self.line5 = [[UILabel alloc] initWithFrame:CGRectMake(20, self.phoneField.nim_bottom + 10, ScreenW - 20, 1)];
    self.line5.backgroundColor = HexColor(0xF2F2F5);
    [self.view addSubview:self.line5];
    
    UILabel *title6Lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 17)];
    title6Lab.text = @"验证码";
    title6Lab.font = BoldFontOfSize(16);
    title6Lab.textColor = HexColor(0x2B2C44);
    self.phoneCodeField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10 + self.line5.nim_bottom, ScreenW - 40, 40)];
    self.phoneCodeField.placeholder = @"请输入";
    self.phoneCodeField.font = MediumFontOfSize(16);
    self.phoneCodeField.textColor = HexColor(0x2B2C44);
    self.phoneCodeField.keyboardType = UIKeyboardTypeNumberPad;
    if (@available(iOS 12.0, *)) {
        self.phoneCodeField.textContentType = UITextContentTypeOneTimeCode;
    } else {
        self.phoneCodeField.textContentType = @"one-time-code";
    }
    self.phoneCodeField.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.phoneCodeField];
    self.phoneCodeField.leftView = title6Lab;
    self.phoneCodeField.leftViewMode = UITextFieldViewModeAlways;
    
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 102, 40)];
    self.getCodeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 5, 102, 30)];
    self.getCodeBtn.layer.cornerRadius = 15;
    [self.getCodeBtn setBackgroundColor:HexColorA(0x3D68EB, 0.1)];
    [self.getCodeBtn setTitleColor:HexColor(0x3D68EB) forState:0];
    [self.getCodeBtn setTitle:@"获取验证码" forState:0];
    self.getCodeBtn.titleLabel.font = BoldFontOfSize(14);
    [self.getCodeBtn addTarget:self action:@selector(getCodeClick) forControlEvents:UIControlEventTouchUpInside];
    [rightView addSubview:self.getCodeBtn];
    self.phoneCodeField.rightView = rightView;
    self.phoneCodeField.rightViewMode = UITextFieldViewModeAlways;
    
    self.line6 = [[UILabel alloc] initWithFrame:CGRectMake(20, self.phoneCodeField.nim_bottom + 10, ScreenW - 20, 1)];
    self.line6.backgroundColor = HexColor(0xF2F2F5);
    [self.view addSubview:self.line6];
    
    [self changeViewWithCarStatus];
    
    self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenH - BottomHeight - 100 - NaviHeight, ScreenW, 100)];
    [self.view addSubview:self.bottomView];
    
    self.agreeBtn = [[UIButton alloc] initWithFrame:CGRectMake(40, 15, 18, 18)];
    [self.agreeBtn setImage:[UIImage imageNamed:isAgree?@"icon_agreement_sel":@"icon_agreement"] forState:0];
    [self.agreeBtn addTarget:self action:@selector(agreeClick) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomView addSubview:self.agreeBtn];
    
    UILabel *lab1 = [[UILabel alloc] initWithFrame:CGRectMake(self.agreeBtn.nim_right, self.agreeBtn.nim_top, [FactoryMethod sizeWithText:@"我已阅读并同意" font:BoldFontOfSize(12) maxSize:CGSizeMake(0, 0)].width, [FactoryMethod sizeWithText:@"我已阅读并同意" font:BoldFontOfSize(12) maxSize:CGSizeMake(0, 0)].height)];
    lab1.text = @"我已阅读并同意";
    lab1.font = BoldFontOfSize(12);
    lab1.textColor = HexColor(0x9C9DB3);
    [self.bottomView addSubview:lab1];
    lab1.nim_centerY = self.agreeBtn.nim_centerY;
    
    self.delegateBtn = [[UIButton alloc] initWithFrame:CGRectMake(lab1.nim_right, lab1.nim_top, [FactoryMethod sizeWithText:@"用户注册及服务协议" font:BoldFontOfSize(12) maxSize:CGSizeMake(0, 0)].width, [FactoryMethod sizeWithText:@"用户注册及服务协议" font:BoldFontOfSize(12) maxSize:CGSizeMake(0, 0)].height)];
    [self.delegateBtn setTitle:@"用户注册及服务协议" forState:0];
    self.delegateBtn.titleLabel.font = BoldFontOfSize(12);
    [self.delegateBtn setTitleColor:HexColor(0x3D68EB) forState:0];
    [self.delegateBtn addTarget:self action:@selector(delegateClick) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomView addSubview:self.delegateBtn];
    self.delegateBtn.nim_centerY = self.agreeBtn.nim_centerY;
    
    self.commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(40, self.agreeBtn.nim_bottom + 15, ScreenW - 80, 44)];
    [self.commitBtn setTitle:@"提交注册" forState:0];
    [self.commitBtn setTitleColor:HexColor(0xffffff) forState:0];
    self.commitBtn.titleLabel.font = BoldFontOfSize(16);
    [self.commitBtn setBackgroundColor:HexColor(0x3D68EB)];
    self.commitBtn.layer.masksToBounds = YES;
    self.commitBtn.layer.cornerRadius = 6;
    [self.commitBtn addTarget:self action:@selector(commitClick) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomView addSubview:self.commitBtn];
}

- (void)changeViewWithCarStatus {
    if (carStatus == 1) {
        self.duoBtn.backgroundColor = HexColor(0xF2F2F5);
        [self.duoBtn setTitleColor:HexColor(0x585974) forState:0];
        self.danBtn.backgroundColor = HexColor(0x3D68EB);
        [self.danBtn setTitleColor:HexColor(0xffffff) forState:0];
        
        self.carCodeField.nim_height = 40;
        self.carCodeField.hidden = NO;
        self.line2.nim_top = self.carCodeField.nim_bottom + 10;
        self.supplierField.nim_top = self.line2.nim_bottom + 10;
        self.line3.nim_top = self.supplierField.nim_bottom + 10;
        self.emailField.nim_top = self.line3.nim_bottom + 10;
        self.line4.nim_top = self.emailField.nim_bottom + 10;
        self.phoneField.nim_top = self.line4.nim_bottom + 10;
        self.line5.nim_top = self.phoneField.nim_bottom + 10;
        self.phoneCodeField.nim_top = self.line5.nim_bottom + 10;
        self.line6.nim_top = self.phoneCodeField.nim_bottom + 10;
    }else {
        self.duoBtn.backgroundColor = HexColor(0x3D68EB);
        [self.duoBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.danBtn.backgroundColor = HexColor(0xF2F2F5);
        [self.danBtn setTitleColor:HexColor(0x585974) forState:0];
        
        self.carCodeField.nim_height = 0;
        self.carCodeField.hidden = YES;
        self.line2.nim_top = self.btnView.nim_bottom + 10;
        self.supplierField.nim_top = self.line2.nim_bottom + 10;
        self.line3.nim_top = self.supplierField.nim_bottom + 10;
        self.emailField.nim_top = self.line3.nim_bottom + 10;
        self.line4.nim_top = self.emailField.nim_bottom + 10;
        self.phoneField.nim_top = self.line4.nim_bottom + 10;
        self.line5.nim_top = self.phoneField.nim_bottom + 10;
        self.phoneCodeField.nim_top = self.line5.nim_bottom + 10;
        self.line6.nim_top = self.phoneCodeField.nim_bottom + 10;
    }
}

- (void)agreeClick {
    isAgree = !isAgree;
    [self.agreeBtn setImage:[UIImage imageNamed:isAgree?@"icon_agreement_sel":@"icon_agreement"] forState:0];
}

- (void)delegateClick {
    RegistDelegateVC *vc = [RegistDelegateVC new];
    [self.rt_navigationController pushViewController:vc animated:YES];
}

- (void)commitClick {
    if (isAgree) {
        [self requestForRegist];
    }else {
        [MBProgressHUD leShowFailedHUD:self.view message:@"请同意用户注册及服务协议"];
    }
}

- (void)textFieldChange:(UITextField *)field {
    [HttpRequest PostWithApi:LogisticsSupplierRegistGetInfo_V_1_0 params:@{@"invite_code":self.inviteCodeField.text} progress:^(NSProgress * _Nonnull progress) {
            
    } success:^(NSURLSessionDataTask * _Nonnull operation, id  _Nonnull responseObject, BOOL code, NSInteger errorCode) {
        if (code) {
            if (field.text.length) {
                NSString *name = [responseObject objectForKey:@"name"];
                if (![FactoryMethod isNull:name]) {
                    self.supplierField.text = name;
                }
                NSString *tel = [responseObject objectForKey:@"tel"];
                if (![FactoryMethod isNull:tel]) {
                    self.phoneField.text = tel;
                }
                NSString *email = [responseObject objectForKey:@"email"];
                if (![FactoryMethod isNull:email]) {
                    self.emailField.text = email;
                }
                int type = [[responseObject objectForKey:@"type"] intValue];
                if (type == 1) {
                    self->carStatus = 1;
                    [self changeViewWithCarStatus];
                }else if (type == 2) {
                    self->carStatus = 2;
                    [self changeViewWithCarStatus];
                }
            }else {
                self.supplierField.text = @"";
                self.phoneField.text = @"";
                self.emailField.text = @"";
            }
            
        }
    } fail:^(NSError * _Nonnull error) {
        
    }];
}

- (void)requestForRegist {
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    if (self.inviteCodeField.text.length) {
        [dic setObject:self.inviteCodeField.text forKey:@"invite_code"];
    }
    if ([FactoryMethod isNull:self.supplierField.text]) {
        [MBProgressHUD leShowFailedHUD:self.view message:@"请输入车主名称"];
        return;
    }else {
        [dic setObject:self.supplierField.text forKey:@"company_name"];
    }
    if (self.emailField.text.length) {
        [dic setObject:self.emailField.text forKey:@"email"];
    }
    if ([FactoryMethod isNull:self.phoneField.text]) {
        [MBProgressHUD leShowFailedHUD:self.view message:@"请输入手机号"];
        return;
    }
    if (![FactoryMethod isPhone:self.phoneField.text]) {
        [MBProgressHUD leShowFailedHUD:self.view message:@"请输入正确的手机号"];
        return;
    }else {
        [dic setObject:self.phoneField.text forKey:@"phone"];
    }
    if ([FactoryMethod isNull:self.phoneCodeField.text]) {
        [MBProgressHUD leShowFailedHUD:self.view message:@"请输入验证码"];
        return;
    }else {
        [dic setObject:self.phoneCodeField.text forKey:@"sms_code"];
    }
    [dic setObject:@(carStatus) forKey:@"type"];
    if (carStatus == 1) {
        if ([FactoryMethod isNull:self.carCodeField.text]) {
            [MBProgressHUD leShowFailedHUD:self.view message:@"请输入车牌"];
            return;
        }else {
            [dic setObject:self.carCodeField.text forKey:@"car_num"];
        }
    }
    
    [MBProgressHUD leShowHUDWithMessage:@"提交中" activity:YES];

    [HttpRequest PostWithApi:LogisticsSupplierRegist_V_1_0 params:dic progress:^(NSProgress * _Nonnull progress) {
            
    } success:^(NSURLSessionDataTask * _Nonnull operation, id  _Nonnull responseObject, BOOL code, NSInteger errorCode) {
        if (code) {
//            __weak_self;
//            [MBProgressHUD leShowSuccessHUDAddedTo:self.view message:@"注册成功" delayOperation:^{
                CommitSuccessVC *vc = [CommitSuccessVC new];
//                vc.companyNO = [responseObject objectForKey:@"company_no"];
                vc.responseObject = responseObject;
                [self.rt_navigationController pushViewController:vc animated:YES];
//            }];
        }
    } fail:^(NSError * _Nonnull error) {
        
    }];
}

- (void)noticeClick {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"如是单车车主，系统会进行相应的简化，有多车后可在系统中“我的”里进行升级操作！" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"关闭" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [cancleAction setValue:Color_ThemeColor forKey:@"titleTextColor"];
    [alert addAction:cancleAction];
    [self presentViewController:alert animated:YES completion:nil];
}

- (void)changeClick {
    if (carStatus == 1) {
        carStatus = 2;
    }else {
        carStatus = 1;
    }
    [self changeViewWithCarStatus];
}

- (void)getCodeClick {
    if ([FactoryMethod isNull:self.phoneField.text]) {
        [MBProgressHUD leShowFailedHUD:self.view message:@"请输入手机号"];
        return;
    }
    if (![FactoryMethod isPhone:self.phoneField.text]) {
        [MBProgressHUD leShowFailedHUD:self.view message:@"请输入正确的手机号"];
        return;
    }
    [self timeStart];
    [self requestForGetCode];
}

- (void)timeStart{
    [self.phoneCodeField becomeFirstResponder];
    self.getCodeBtn.userInteractionEnabled = NO;
    self.phoneCodeField.text = @"";
    __block int timeout = 60; //倒计时时间
    /**
     *  gcd异步处理倒计时控件
     */
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout<=0){ //倒计时结束，关闭
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                self.getCodeBtn.userInteractionEnabled = YES;
                [self.getCodeBtn setTitle:@"重新获取" forState:UIControlStateNormal];
                [self.getCodeBtn setTitleColor:HexColor(0x3D68EB) forState:UIControlStateNormal];
            });
        }else{
            int seconds = timeout;
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                self.getCodeBtn.userInteractionEnabled = NO;
                NSString *strTime = [NSString stringWithFormat:@"%d S",seconds];
                [self.getCodeBtn setTitle:strTime forState:(UIControlStateNormal)];
                [self.getCodeBtn setTitleColor:HexColor(0x2B2C44) forState:UIControlStateNormal];
            });
            timeout--;
        }
    });
    dispatch_resume(_timer);
}

- (void)requestForGetCode {
    [MBProgressHUD leShowHUDWithMessage:@"请求中" activity:YES];
    [HttpRequest PostWithApi:LogisticsSupplierGetCode_V_1_0 params:@{@"phone":self.phoneField.text,@"type":@"2"} progress:^(NSProgress * _Nonnull progress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull operation, id  _Nonnull responseObject, BOOL code, NSInteger errorCode) {
        if (code) {
            [MBProgressHUD leShowSuccessHUDAddedTo:self.view message:@"验证码获取成功"];
        }
    } fail:^(NSError * _Nonnull error) {
        
    }];
}

@end
